<template>
  <div class="app-container animated fadeIn">
    <el-row :gutter="10" class="mb8">
      <el-col :span="12">
        <el-form inline>
          <el-form-item label="日期:">
            <el-date-picker
              v-model="date"
              placeholder="查询日期"
              style="width: 200px"
              format="yyyy-MM-dd 星期dddd"
              autocomplete="off"
              :clearable="false"
              @change="changeBcdm"></el-date-picker>
          </el-form-item>
          <el-form-item label="班次代码:">
            <el-radio-group v-model="BcDm" size="large" style="padding-left: 15px" @change="changeBcdm">
              <el-radio label="白班"></el-radio>
              <el-radio label="夜班"></el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <div>
      <div style="text-align: center">
        <h1 style="color: crimson; font-weight: bold; font-size: 32px">入库差异报表</h1>
      </div>
      <div style="float: right; font-size: 18px; font-weight: bold; position: absolute; right: 32px">
        <span>时间:</span>
        <span>{{ curTime }}</span>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      </div>
      <div class="rkpb">
        <table>
          <tr>
            <th style="width: 150px">客户编码</th>
            <th style="width: 120px">班次</th>
            <th style="width: 100px">入库数</th>
            <th style="width: 100px">机台产能</th>
          </tr>
          <tr v-for="row in tabrkpb.tab">
            <td>{{ row.rpdWldm }}</td>
            <td>{{ row.rpmBcdm }}</td>
            <td>{{ row.sum }}</td>
            <td>{{ row.totalNum }}</td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
import {listWarehousingDifference} from "@/api/production/ComparativeAnalysis";

export default {
  name: 'WarehousingDifference',
  data() {
    return {
      date: this.$moment().format('YYYY-MM-DD'),
      BcDm: '白班',
      tabrkpb: { cols: 1, tab: [] },
    }
  },
  created() {
    this.changeBcdm()
  },
  computed: {
    curTime() {
      return this.$moment(this.date).format('YYYY年M月D日') + ' ' + this.BcDm
    },
  },
  methods: {
    changeBcdm() {
      let dat = this.$moment(this.date)
      dat = this.BcDm === '白班' ? dat.hour(9) : dat.hour(21)
      listWarehousingDifference({
        rpdRkDate: this.$moment(dat).format('YYYY-MM-DD HH:mm:ss'),
        rpmBcdm: this.BcDm,
      })
        .then((res) => {
          this.tabrkpb.cols = 1
          this.tabrkpb.tab = res.data.map((a) => {
            let b = a.number.split(',')
            this.tabrkpb.cols = Math.max(this.tabrkpb.cols, b.length)
            a.num = b
            a.sum = b.reduce((p, c) => p + parseInt(c), 0)
            return a
          })
        })
        .catch((err) => {
          alert(err + '网络原因：请检查网络连接或服务器状态')
          console.log(err + '网络原因：请检查网络连接或服务器状态')
        })
    },
  },
}
</script>

<style scoped lang="less">
.rkpb {
  margin: 32px 0px 0px 20px;
  table {
    table-layout: fixed;
    border: 1px solid black;
    border-collapse: collapse;
    text-align: center;
    line-height: 32px;
    font-size: 18px;
    td,
    th {
      border: 1px solid black;
    }
  }
}
</style>
